#ifndef MDX_H
#define MDX_H

#include "MDictBase.h"

class MDX : public MDictBase {
    struct RecordInfo {
        // 对应的记录块的（压缩状态）偏移量，记录块文件读取需要
        uint64_t tellg_;
        // 对应的记录块的（解压状态）开头位置的偏移量。查询指定key的记录对比的偏移量
        uint64_t offset_start;
        // 对应的记录块的解压之后的长度
        uint64_t decompressed_size;
        // 对应的记录块的压缩状态的长度
        uint64_t compressed_size;
    };

private:
    bool m_substyle;
    uint64_t m_record_chunks_offset;
    vector<RecordInfo> m_recordInfos;
    void parseRecordBlockInfo();
    vector<uint8_t> _treat_record_data(const vector<uint8_t>& data);
    vector<uint8_t> _substitute_stylesheet(const vector<uint8_t>& txt);
    void test();

protected:
    vector<pair<string, vector<uint8_t>>> _read_records() override;

public:
    MDX(const string& fname, const string& encoding = "", bool substyle = false,
        const pair<vector<uint8_t>, string>& passcode = {});
    vector<pair<string, vector<uint8_t>>> items() override;
    string query(string key);
    string metaInfo();
};

#endif  // MDX_H
